/**
 * ExportService.java 
 * Copyright © 2015-3015, 杭州泊享网络科技有限公司
 * 
 * @author Liu Tao
 * @create 2015年1月17日
 */
package com.pshare.artemis.common.service;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pshare.excel.service.ExcelExportService;
import com.pshare.msg.email.service.MailService;

/**
 * 文件导出业务层
 */
@Service
public class ExportService {

	private static final Logger logger = Logger.getLogger(ExportService.class);
	
	@Autowired
	private MailService mailService;
	
	/**
	 * 导出excel，并通过email发送
	 * @param excelExportService
	 * @param dataList
	 * @param receiver 收件人
	 */
	public void exportWithEmail(ExcelExportService excelExportService, List dataList, String receiver) {
		logger.info("begin to export file to " + receiver);
		String filePath = excelExportService.generateExcel(dataList);
		File file = new File(filePath);
		List<File> files = new ArrayList<File>();
		files.add(file);
		String[] receivers = new String[] {receiver};
		mailService.sendMail("EMM文件导出", "请下载附件", files, receivers, null, null);
		logger.info("complete exporting file");
	}
}
